package com.fjrz.bbxwj.listener

import android.content.Context
import android.view.Gravity
import android.widget.TextView
import androidx.annotation.ColorRes
import com.blankj.utilcode.util.ColorUtils
import com.fjrz.bbxwj.R
import com.google.android.material.tabs.TabLayout

class TabSelectedListener(val context: Context,@ColorRes var resId:Int) : TabLayout.OnTabSelectedListener {
    override fun onTabReselected(tab: TabLayout.Tab?) = Unit

    override fun onTabUnselected(tab: TabLayout.Tab?) {
        tab?.customView = null
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        val text: TextView = TextView(context).apply {
            setTextColor(ColorUtils.getColor(resId))
            textSize = 16f
            gravity = Gravity.CENTER
            paint.isFakeBoldText = true
        }
        text.text = tab?.text
        tab?.customView = text
    }
}